package com.njwb.day15.zqzb.method.ann4;

import java.lang.reflect.Method;

public class Dbutil {

    @MySqlInfo(driverClassName = "com.mysql.driver.MysqlDriver" ,url ="jdbc:mysql://localhost",username = "root",password ="root")
    public void  conectionMysql() {
        try {
            Method m = Dbutil.class.getDeclaredMethod("conectionMysql",new Class[] {});
            if(m.isAnnotationPresent(MySqlInfo.class)){
                MySqlInfo annotation = m.getAnnotation(MySqlInfo.class);
                System.out.println("驱动的名字："+annotation.driverClassName());
                System.out.println("url地址："+annotation.url());
                System.out.println("用户名："+annotation.username());
                System.out.println("密码："+annotation.password());
                //后续根据需要自行编写。
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        //获取连接参数并打印。
        System.out.println("连接成功");
    }
    public static void main(String[] args) {
        new Dbutil().conectionMysql();
    }
}
